package com.lagouedu.controller;

import com.lagouedu.dto.LoginDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@Slf4j
public class LoginController {

    @RequestMapping("/index")
    public String index() {
        System.out.println("进入index");
        return "login/loginHtml";
    }

    @RequestMapping("/login")
    public String login(LoginDTO loginDTO, HttpServletRequest request) {
        String username = loginDTO.getUsername();
        String password = loginDTO.getPassword();
        log.info("用户名：{},密码：{}", username, password);
        if ("admin".equals(username) && "admin".equals(password)) {
            request.getSession().setAttribute("username",username + "-" + password);
            System.out.println("登陆成功");
            return "login/loginSuccess";
        }
        System.out.println("登陆失败");
        return "redirect:index";
    }

    @RequestMapping("/loginSuccess")
    public String loginSuccess() {
        System.out.println("登陆成功接口，需要拦截器");
        return "login/loginSuccess";
    }


}
